package nl.han.ica.ap.searchengine.client.controller;

import java.awt.EventQueue;

import nl.han.ica.ap.searchengine.client.Engine;
import nl.han.ica.ap.searchengine.client.SearchQuery;
import nl.han.ica.ap.searchengine.client.view.SearchEngineGui;

/**
 * Controller to facilitate communication between the engine and a/the GUI
 * 
 * @author A.J. Janssen, ...
 * @version 0.1
 *
 */
public class SearchEngineController 
{
	private SearchEngineGui gui;
	private Engine engine;
	
	public SearchEngineController()
	{
		
	}
	
	public SearchEngineController(Engine engine)
	{
		this.engine = engine;
	}

	public void setGui(SearchEngineGui gui) {
		this.gui = gui;
	}

	public void setEngine(Engine engine) {
		this.engine = engine;
	}
	
	public void performSearch(final SearchQuery query)
	{
		//This request is processed in a new thread as to avoid locking up the GUI
		EventQueue.invokeLater(new Runnable() {
			public void run() 
			{
				gui.takeResults(engine.processQuery(query));
			}
		});
	}
}
